/**
 * 录取信息管理初始化
 */
var Admission = {
    id: "AdmissionTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Admission.initColumn = function () {
    return [
            {title: '主键ID', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: '准考证号', field: 'examCardNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '考生姓名', field: 'studentName', visible: true, align: 'center', valign: 'middle'},
            {title: '考场号', field: 'examSiteNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '座位号', field: 'seatNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '建档号', field: 'archivesNumber', visible: true, align: 'center', valign: 'middle'},
            {title: '录取学校代码', field: 'enterSchoolCode', visible: true, align: 'center', valign: 'middle'},
            {title: '录取学校名称', field: 'enterSchoolName', visible: true, align: 'center', valign: 'middle'},
            {title: '录取专业代码', field: 'enterClassCode', visible: true, align: 'center', valign: 'middle'},
            {title: '录取专业名称', field: 'enterClassName', visible: true, align: 'center', valign: 'middle'} 
    ];
};

/**
 * 检查是否选中
 */
Admission.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
    	Admission.seItem = selected[0];
    	
        return true;
    }
};

/**
 * 点击添加录取信息
 */
Admission.openAddAdmission = function () {
    var index = layer.open({
        type: 2,
        title: '添加学生录取信息',
        area: ['60%', '60%'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/importAdmission/add'
    });
    this.layerIndex = index;
};
/**
 * 打开查看录取信息详情
 */
Admission.openChangeAdmission = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '考生录取详情',
            area: ['60%', '60%'], //宽高
            fix: false, //不固定
            maxmin: true,
            content:Feng.ctxPath + '/importAdmission/edit?id=' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除录取信息
 */

Admission.delScore = function () {
    if (this.check()) {

    	Feng.confirm("是否删除考生" + Admission.seItem.studentName + "？",function(){
	        var ajax = new $ax(Feng.ctxPath + "/importAdmission/remove", function (data) {
	            Feng.success("删除成功!");
	            Admission.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("id",Admission.seItem.id);
	        ajax.start();
    	 });
    		
    }
    
    /**
     *  if (this.check()) {
    	var operation ;
    	Feng.confirm("是否删除考生" + ExamineeScore.seItem.studentName + "？",operation);
    	
    	 operation = function(){
	        var ajax = new $ax(Feng.ctxPath + "/inputMidScore/remove", function (data) {
	            Feng.success("删除成功!");
	            ExamineeScore.table.refresh();
	        }, function (data) {
	            Feng.error("删除失败!" + data.responseJSON.message + "!");
	        });
	        ajax.set("examineeScoreId",ExamineeScore.seItem.id);
	        ajax.start();
    	 };
    	
    }
     */
};

/**
 * 模板下载
 */
Admission.templateDown = function () {
	var operation = function(){
		location.href=Feng.ctxPath + "/static/file/中考录取信息导入模板.xlsx";
	 };
	 Feng.confirm("确定下载中考录取信息导入模板？",operation);
};


/**
 * 录取信息导入
 */

Admission.importAdmission = function () {
	 //定义上传文件对象
    var webUploaderObj = new $WebUpload("admission");
    //设置允许上传的文件类型（在web-upload-object中定义了类型）
    webUploaderObj.setAcceptFileType("excel");
    //设置文件上传地址
    webUploaderObj.setUploadUrl(Feng.ctxPath + "/importAdmission/import");
    //获取webUploader对象，调用create方法，手动绑定事件
    var webUploader = webUploaderObj.create();
    //绑定事件
    webUploader.on('uploadSuccess', function (file, response) {
        Feng.infoDetail("导入结果", response.message.split("\n"), '500px', '500px');
        Admission.table.refresh();
    });
    // 文件上传失败，显示上传出错。
    webUploader.on('uploadError', function (file, response) {
        Feng.error("上传失败");
    });
};

Admission.resetSearch = function () {
    $("#examCardNumber").val("");
    $("#studentName").val("");
    $("#schoolName").val("");
    Admission.search();
}

/**
 * 查询考试信息列表
 */
Admission.search = function () {
    var queryData = {};
    queryData['examCardNumber'] = $("#examCardNumber").val();
    queryData['studentName'] = $("#studentName").val();
    queryData['schoolName'] = $("#schoolName").val();
    Admission.table.refresh({query: queryData});
};

$(function () {
    var defaultColumns = Admission.initColumn();
    var table = new BSTable(Admission.id, "/importAdmission/list", defaultColumns);
    Admission.table = table.init();
    Admission.importAdmission() ;
});
